﻿/*

###########################################################
#                                                           #
#     #  #         #  #                                     #
#     # #    ###   # #   ###      ###   ###    ##   ###     #
#     ##    #   #  ##   #   #    #   # #   #  # #  #   #    #
#     ##    #####  ##   #####       #  #   #    #  #   #    #
#     # #   #      # #  #          #   #   #    #  #   #    #
#     #  #   ###   #  #  ###  # # ####  ###    ###  ###     #
#                                                           #
###########################################################
________________________________________________________

name script: سكربت كشف الهجمات
Upload date : 21.02.2014 - time: 10:22
data     : 2013
name     : fessal
Nickname : keke..2010
url      : http://forum.tribalwars.ae/member.php?u=24151
url      : www.tribalwars.ae
skype    : keke..2010
email    : boob-77@hotmail.com
__________________________________________________

Copyright (C) 2014 (keke..2010), all rights reserved
version 3 , 21 February 2014
________________________________________

*/


$(function(){
    $("#villages_list tbody tr").each(function(){
        $(this).append("<td></td>");
        $(this).append("<td></td>");
        $(this).append("<td></td>");
        $(this).append("<td></td>");
    });
});

$(function(){
    $(".vis:eq(0)").append("<tr><td colspan='2' ><img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/green.png' /> حجز تابع لك</td></tr><tr><td colspan='2' ><img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/yellow.png' />ليس عليها حجز</td></tr><tr><td colspan='2'><img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/red.png' />حجز تابع لأعضاء القبيله</td></tr><tr><td colspan='2' ><img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/blue.png' />حجز تابع للحلفاء</td></tr>");
});


$(function(){
    $(".vis:eq(0)").append("<tr><td><button id='AT'>إرسال</button></td><td><button id='BH'>حجز</button></td></tr>");
    
    $("<h4>تم برمجة السكربت من قبل <a href=http://forum.tribalwars.ae/member.php?u=24151 target=keke >keke..2010</a></h4></br>").prependTo("h2");
    
    $("#AT").click(function(){
        
        var villageAT = document.URL.match(/village=\d+/);
        $("#villages_list tbody tr").each(function(){
            var village2AT = $(this).find("a").attr("href").match(/\d+/g)[1];
            var urlA = '/game.php?'+villageAT+'&target='+village2AT+'&screen=place';
            window.open(urlA);
        });
    });
});


$("#villages_list tbody tr ").each(function(){
    
    var keke = $(this).find("a").attr("href").match(/\d+/g)[1];
    var village1 = document.URL.match(/village=\d+/);
    var urlA = '/game.php?'+village1+'&target='+keke+'&screen=place';
    
    $(this).find("td:eq(5)").append("<center><a id='A' target='keke'><img src='http://cdn.tribalwars.ae/8.19/19798/graphic/unit/att.png' title='إرسال الجيوش' /></a></center>");
    $(this).find("#A").attr("href",urlA);   
    
});

$(function(){
    
    $("#villages_list tbody tr").each(function(){
        
        var x = $(this).find("td:eq(1)").text().match(/\d/g)[0];
        var y = $(this).find("td:eq(1)").text().match(/\d/g)[3];
        
        $(this).find("td:eq(3)").text('K'+y+x);
        
        
        
    });
});

$(function(){
    $("#villages_list thead tr").append("<th>K</th>");
    $("#villages_list thead tr").append("<th>عدد</th>");
    $("#villages_list tbody tr").each(function(){
        var url = $(this).find("a").attr("href");
        var keke = $(this).find("td:eq(4)");
        $.ajax({
            url: url,
            datatype: "xml",
            success : function(data){
                var attack = $(data).find("div .vis th:eq(0)").text().match(/\d+/);
                if(attack != null){
                    $(keke).text('('+attack+')');
                }else{
                    $(keke).text('(0)');
                }
            }
        });
    });
});







$(function(){
    $("<th>إرسال</th>").appendTo("#villages_list thead tr");
    $("<th>حجز</th>").appendTo("#villages_list thead tr");
    var na1 = $("#villages_list tbody tr td:eq(0)").find("a").attr("href");
    
    var village = document.URL.match(/village=\d+/);
    var keke = $("#villages_list tbody tr td:eq(0)").find("a").attr("href").match(/\d+/g)[1];
    var url1 = '/game.php?'+village+'&id='+keke+'&screen=info_village';
    
    $.ajax({
        url : url1,
        datatype: "xml",
        success : function (data){
            
            var m = $(data).find(".vis:eq(0) tr:eq(9)").find("a").attr("href").match(/h=\S+/);
            
            $("#villages_list tbody tr ").each(function(){
                var keke = $(this).find("a").attr("href").match(/\d+/g)[1];
                
                var village1 = document.URL.match(/village=\d+/);
                var urlA = '/game.php?'+village+'&target='+keke+'&screen=place';
                var urlH = '/game.php?'+village+'&id='+keke+'&action=reserve_village&'+m;
                
                
                $(this).find("td:eq(6)").append("<a id='B' target='keke'><img src='http://cdn.tribalwars.ae/8.19/19798/graphic/forum/thread_close.png' title='حجز القريه' /></a>");
                $(this).find("#B").attr("href",urlH);
                
                
                $("#BH").click(function(){
                    
                    window.open(urlH);
                    
                });
                
                
            });
        }
    });
});

$(function(){
    
    var player = game_data.player.id;
    var ally = game_data.player.ally;
    
    $("#villages_list tbody tr ").each(function(){
        var THQ = $(this).find("a").attr("href");
        var keke = $(this).find("td:eq(0)");
        $.ajax({
            url : THQ,
            datatype: "xml",
            success : function (data){
                
                var allyId = $(data).find(".main .vis tr:eq(5) td:eq(1)").find("a:eq(1)").attr("href").match(/\d+/g)[1];
                var id = $(data).find(".main .vis tr:eq(5) td:eq(1)").find("a").attr("href").match(/\d+/g)[1];
                
                if(allyId != ally){
                    $(keke).append("<img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/blue.png' />");
                    
                } else  if(id != player){
                    $(keke).append("<img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/red.png' />");
                    
                } else  if(id == player){
                    $(keke).append("<img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/green.png' />");
                    
                } 
                    
                    }
        });
    });
});

$(function(){
    $("#villages_list tbody tr ").each(function(){
        var THQ = $(this).find("a").attr("href");
        var keke = $(this).find("td:eq(0)");
        $.ajax({
            url : THQ,
            datatype: "xml",
            success : function (data){
                
                var map = $(data).find(".main .vis tr:eq(5) td:eq(1)").find("a").attr("href");
                
                if(map == undefined ){
                    $(keke).append("<img src='http://cdn.tribalwars.ae/8.19/19747/graphic/dots/yellow.png' />");
                    
                }        
            }
        });
    });
});


